export class Cookie {

  constructor() {
    this.path = ';path=/' + (/\d+\.\d+\.\d+\.\d+/.test(document.domain) ? '' :
      ';domain=.' + location.host);
    this.expr = /=|;/;
  }

  set(name, value, days = 365) {
    var expire = new Date;
    expire.setDate(expire.getDate() + days);
    document.cookie = [name, '=', value, ';expires=', expire.toUTCString(),
      this.path].join('');
  }

  get(name) {
    return (name = (document.cookie + ';').match(new RegExp(name + '=.*;'))) &&
      name[0].split(this.expr)[1];
  }

  remove(name) {
    this.set(name, '', -1);
  }

}